package com.dt.platform.generator.module.oa;

import com.dt.platform.constants.db.OaTables;
import com.dt.platform.constants.enums.common.StatusEnableEnum;
import com.dt.platform.constants.enums.oa.ProjectStatusEnum;
import com.dt.platform.domain.oa.Project;
import com.dt.platform.domain.oa.ProjectDoc;
import com.dt.platform.domain.oa.ProjectPhase;
import com.dt.platform.domain.oa.meta.ProjectMeta;
import com.dt.platform.domain.oa.meta.ProjectTaskMeta;
import com.dt.platform.generator.config.Config;
import com.dt.platform.oa.page.ProjectPageController;
import com.dt.platform.proxy.oa.ProjectServiceProxy;
import com.foxnicweb.web.domain.contract.Contract;
import com.foxnicweb.web.domain.contract.meta.ContractMeta;
import com.foxnicweb.web.proxy.contract.ContractServiceProxy;
import com.github.foxnic.generator.builder.view.config.DatePickerType;
import com.github.foxnic.generator.config.WriteMode;
import org.github.foxnic.web.domain.hrm.Employee;
import org.github.foxnic.web.domain.hrm.Organization;
import org.github.foxnic.web.domain.system.DictItem;
import org.github.foxnic.web.domain.system.meta.DictItemMeta;
import org.github.foxnic.web.proxy.system.DictItemServiceProxy;

public class AProjectGtr extends BaseCodeGenerator {


    public AProjectGtr() {
        super(OaTables.OA_PROJECT.$TABLE,"705020984087805957");
    }

    public void generateCode() throws Exception {
        System.out.println(this.getClass().getName());

        cfg.view().field(OaTables.OA_PROJECT.ID).basic().hidden(true);
        cfg.view().field(OaTables.OA_PROJECT.NAME).search().fuzzySearch();

        cfg.getPoClassFile().addSimpleProperty(Employee.class,"owner","owner","owner");
        cfg.getPoClassFile().addSimpleProperty(Employee.class,"leader","leader","leader");
        cfg.getPoClassFile().addListProperty(Employee.class,"partUserList","partUserList","partUserList");
        cfg.getPoClassFile().addListProperty(String.class,"partUserStrList","partUserStrList","partUserStrList");
        cfg.getPoClassFile().addSimpleProperty(DictItem.class,"workTypeDict","workTypeDict","workTypeDict");
        cfg.getPoClassFile().addSimpleProperty(Contract.class,"contract","contract","contract");
        cfg.getPoClassFile().addSimpleProperty(Organization.class,"organization","organization","organization");
        cfg.getPoClassFile().addSimpleProperty(String.class,"selectedCode","selectedCode","selectedCode");
        cfg.getPoClassFile().addSimpleProperty(String.class,"selectRange","selectRange","selectRange");
        cfg.getPoClassFile().addSimpleProperty(String.class,"taskCount","taskCount","taskCount");
        cfg.getPoClassFile().addSimpleProperty(String.class,"taskActingCount","taskActingCount","taskActingCount");
        cfg.getPoClassFile().addSimpleProperty(String.class,"taskCompleteCount","taskCompleteCount","taskCompleteCount");
        cfg.getPoClassFile().addSimpleProperty(String.class,"taskCompletePct","taskCompletePct","taskCompletePct");
        cfg.getPoClassFile().addSimpleProperty(String.class,"planTimeRange","planTimeRange","planTimeRange");
        cfg.getPoClassFile().addSimpleProperty(String.class,"workTimeTotal","workTimeTotal","workTimeTotal");

        cfg.getPoClassFile().addSimpleProperty(String.class,"planWorkTimeTotal","planWorkTimeTotal","planWorkTimeTotal");

        cfg.getPoClassFile().addSimpleProperty(String.class,"taskStat","taskStat","taskStat");
        cfg.getPoClassFile().addSimpleProperty(ProjectPhase.class,"ProjectPhase","projectPhase","projectPhase");

        cfg.getPoClassFile().addListProperty(ProjectPhase.class,"ProjectPhaseList","ProjectPhaseList","ProjectPhaseList");

        cfg.getPoClassFile().addSimpleProperty(String.class,"taskRcdCount","taskRcdCount","taskRcdCount");

        cfg.getPoClassFile().addSimpleProperty(String.class,"tabStatus","tabStatus","tabStatus");

        cfg.view().form().addJsVariable("CUR_EMP_ID","[[${curEmpId}]]","curEmpId");
        cfg.view().form().addJsVariable("CUR_USER_NAME","[[${curUserName}]]","curUserName");

        cfg.view().form().addJsVariable("CUR_USER_ORG_ID","[[${curUserOrgId}]]","curUserOrgId");
        cfg.view().form().addJsVariable("CUR_USER_ORG_NAME","[[${curUserOrgName}]]","curUserOrgName");



        cfg.view().field(ProjectMeta.PLAN_WORK_TIME_TOTAL).basic().label("计划工时");
        cfg.view().field(ProjectMeta.WORK_TIME_TOTAL).basic().label("实际工时");
        cfg.view().field(ProjectMeta.TASK_COUNT).basic().label("任务总数");


        cfg.view().field(ProjectMeta.TASK_ACTING_COUNT).basic().label("进行中任务数");
        cfg.view().field(ProjectMeta.TASK_COMPLETE_COUNT).basic().label("已完成任务数");
        cfg.view().field(ProjectMeta.TASK_COMPLETE_PCT).basic().label("任务完成率");
        cfg.view().field(ProjectMeta.PLAN_TIME_RANGE).basic().label("项目计划周期");
        cfg.view().field(ProjectMeta.TASK_STAT).basic().label("进行中/已完成任务数");



        cfg.view().field(ProjectMeta.PLAN_WORK_TIME_TOTAL).table().disable(true);
        cfg.view().field(ProjectMeta.TASK_RCD_COUNT).table().disable(true);
        cfg.view().field(ProjectMeta.TAB_STATUS).table().disable(true);

        cfg.view().field(ProjectMeta.TASK_COUNT).table().disable(true);
        cfg.view().field(ProjectMeta.TASK_ACTING_COUNT).table().disable(true);
        cfg.view().field(ProjectMeta.TASK_COMPLETE_COUNT).table().disable(true);


        cfg.view().field(OaTables.OA_PROJECT.CREATE_TIME).search().range();
        cfg.view().field(OaTables.OA_PROJECT.CODE).search().fuzzySearch();
        cfg.view().field(OaTables.OA_PROJECT.NAME).search().fuzzySearch();
        cfg.view().list().disableBatchDelete();

        cfg.view().search().inputLayout(
                new Object[]{
                        OaTables.OA_PROJECT.PROJECT_STATUS,
                        OaTables.OA_PROJECT.LEADER_ID,
                        OaTables.OA_PROJECT.TYPE,
                        OaTables.OA_PROJECT.CODE,

                },
                new Object[]{
                        OaTables.OA_PROJECT.NAME,
                        OaTables.OA_PROJECT.SDATE,
                }
        );

        cfg.view().field(OaTables.OA_PROJECT.SDATE).form().validate().required().form().dateInput().format("yyyy-MM-dd").defaultNow().type(DatePickerType.date).search().range();
        cfg.view().field(OaTables.OA_PROJECT.EDATE).form().validate().required().form().dateInput().format("yyyy-MM-dd").defaultNow().type(DatePickerType.date).search().range();


        cfg.view().field(OaTables.OA_PROJECT.OWNER_ID).table().fillBy("owner","name");
        cfg.view().field(OaTables.OA_PROJECT.OWNER_ID).form()
                .button().chooseEmployee(true);

        cfg.view().field(OaTables.OA_PROJECT.LEADER_ID).table().fillBy("leader","name");
        cfg.view().field(OaTables.OA_PROJECT.LEADER_ID).form().validate().required().form()
                .button().chooseEmployee(true);

        cfg.view().field(OaTables.OA_PROJECT.ORG_ID)
                .form().validate().required().form().button().chooseOrganization(true);

        cfg.view().search().labelWidth(1,Config.searchLabelWidth);
        cfg.view().search().labelWidth(2,Config.searchLabelWidth);
        cfg.view().search().labelWidth(3,Config.searchLabelWidth);
        cfg.view().search().labelWidth(4,Config.searchLabelWidth);
        cfg.view().search().inputWidth(Config.searchInputWidth);

        cfg.view().field(OaTables.OA_PROJECT.FILE_ID).form().upload().maxFileCount(10);
        cfg.view().field(OaTables.OA_PROJECT.NAME).form().validate().required();

        cfg.view().field(OaTables.OA_PROJECT.PROJECT_STATUS).form().selectBox().enumType(ProjectStatusEnum.class).defaultIndex(0);



        cfg.view().field(OaTables.OA_PROJECT.TYPE)
                .form().validate().required().form().selectBox().queryApi(DictItemServiceProxy.QUERY_PAGED_LIST+"?dictCode=oa_project_type")
                .paging(true).filter(true).toolbar(true).defaultIndex(0)
                .valueField(DictItemMeta.CODE).
                textField(DictItemMeta.LABEL).
                fillWith(ProjectMeta.WORK_TYPE_DICT).muliti(false);


        cfg.view().field(OaTables.OA_PROJECT.CONTRACT_ID)
                .form().selectBox().queryApi(ContractServiceProxy.QUERY_PAGED_LIST)
                .paging(true).filter(true).toolbar(true)
                .valueField(ContractMeta.ID).
                textField(ContractMeta.TITLE).
                fillWith(ProjectMeta.CONTRACT).muliti(false);

        cfg.view().field(ProjectMeta.PART_USER_STR_LIST).basic().label("项目成员").form()
                .button().chooseEmployee(false);


        cfg.view().formWindow().bottomSpace(120);
        cfg.view().formWindow().width(Config.baseFormWidth);
        cfg.view().form().addGroup(null,
                new Object[] {
                        OaTables.OA_PROJECT.NAME,
                },
                new Object[] {
                        OaTables.OA_PROJECT.TYPE,
                }
//                new Object[] {
//                        OaTables.OA_PROJECT.PROJECT_STATUS,
//                }
        );

        cfg.view().form().addGroup(null,
                new Object[] {
                        OaTables.OA_PROJECT.LEADER_ID,
                        OaTables.OA_PROJECT.CONTRACT_ID,
                },
                new Object[] {
                        OaTables.OA_PROJECT.SDATE,
                        OaTables.OA_PROJECT.EDATE,
                },
                new Object[] {
                        OaTables.OA_PROJECT.ORG_ID,
                }

        );

        cfg.view().form().addGroup(null,
                new Object[] {
                        ProjectMeta.PART_USER_STR_LIST,
                        OaTables.OA_PROJECT.PROFILE,
                        OaTables.OA_PROJECT.FILE_ID,
                }
        );

        cfg.view().field(OaTables.OA_PROJECT.UPDATE_BY).table().disable(true);
        cfg.view().field(OaTables.OA_PROJECT.UPDATE_TIME).table().disable(true);
        cfg.view().field(OaTables.OA_PROJECT.CREATE_BY).table().disable(true);

        cfg.view().field(OaTables.OA_PROJECT.ORG_ID).table().disable(true);

        cfg.view().field(OaTables.OA_PROJECT.CONTRACT_ID).table().disable(true);
        cfg.view().field(OaTables.OA_PROJECT.EDATE).table().disable(true);
        cfg.view().field(OaTables.OA_PROJECT.PROFILE).table().disable(true);
        cfg.view().field(ProjectMeta.PART_USER_STR_LIST).table().disable(true);
        cfg.view().field(ProjectMeta.PART_USER_LIST).table().disable(true);
        cfg.view().field(OaTables.OA_PROJECT.FILE_ID).table().disable(true);
        cfg.view().field(OaTables.OA_PROJECT.SDATE).table().disable(true);
        cfg.view().field(OaTables.OA_PROJECT.EDATE).table().disable(true);

        cfg.view().list().columnLayout(
                OaTables.OA_PROJECT.CODE,
                OaTables.OA_PROJECT.PROJECT_STATUS,
                OaTables.OA_PROJECT.TYPE,
                OaTables.OA_PROJECT.NAME,
                OaTables.OA_PROJECT.LEADER_ID,
                OaTables.OA_PROJECT.CUR_PHASE,
                ProjectMeta.PLAN_TIME_RANGE,
                ProjectMeta.TASK_STAT,
//                ProjectMeta.TASK_ACTING_COUNT,
//                ProjectMeta.TASK_COMPLETE_COUNT,
                ProjectMeta.TASK_COMPLETE_PCT,
                ProjectMeta.WORK_TIME_TOTAL,
                OaTables.OA_PROJECT.CREATE_TIME);

        cfg.view().form().addPage("phase","项目阶段","phase");

        cfg.view().list().operationColumn().addActionButton("关闭","actionClose","action-close");
        cfg.view().list().operationColumn().addActionButton("开启","actionOepn","action-open");
        cfg.view().list().addJsVariable("DATA_RANGE","[[${dataRange}]]","dataRange");
        cfg.view().list().addJsVariable("PAGE_TYPE","[[${pageType}]]","pageType");

        //文件生成覆盖模式
        cfg.overrides()
                .setServiceIntfAnfImpl(WriteMode.IGNORE) //服务与接口
                .setControllerAndAgent(WriteMode.IGNORE) //Rest
                .setPageController(WriteMode.IGNORE) //页面控制器
                .setFormPage(WriteMode.COVER_EXISTS_FILE) //表单HTML页
                .setListPage(WriteMode.COVER_EXISTS_FILE)
                .setExtendJsFile(WriteMode.IGNORE); //列表HTML页
        //列表HTML页
        //生成代码

//        cfg.overrides().setServiceIntfAnfImpl(WriteMode.IGNORE);
//        cfg.overrides().setControllerAndAgent(WriteMode.IGNORE);
//        cfg.overrides().setPageController(WriteMode.IGNORE);
//        cfg.overrides().setExtendJsFile(WriteMode.WRITE_TEMP_FILE);

        cfg.buildAll();
    }

    public static void main(String[] args) throws Exception {
        AProjectGtr g=new AProjectGtr();
        //生成代码
        g.generateCode();

        //移除之前生成的菜单，视情况执行
//        g.removeByBatchId("471622036347682816");
        //生成菜单
       // g.generateMenu(ProjectServiceProxy.class, ProjectPageController.class);
    }

}
